#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pokemon_server.srv import PoseState,PoseStateResponse
import threading
import json
import os
import pandas as pd
import sys
R = threading.Lock()
data_path=r'/tmp/data.json'
excel_path = sys.path[0] + r'/dest_pose.xlsx'
# PoseState类，存储机器人所有位姿信息
def init_poses():
    _poses = pd.read_excel(excel_path)
    poses = []
    for i in _poses.values:
        temp =PoseState()
        temp.position_x=i[1]
        temp.position_y=i[2]
        temp.position_z=i[3]
        temp.orientation_x=i[4]
        temp.orientation_y=i[5]
        temp.orientation_z=i[6]
        temp.orientation_w=i[7]
        poses.append(temp)
    return poses
all_pose = init_poses()
def init_state():
    # 0代表未访问，1代表正在访问，2代表已访问
    num=len(all_pose)
    all_state=[0 for i in range(num)]
    with open(data_path, 'w+') as f:
        json.dump(all_state, f)

def get_state(index):
    R.acquire()
    with open(data_path, 'r') as f:
        data = json.load(f)
    R.release()
    return data[index]


def change_state(index,state):
    R.acquire()
    with open(data_path, 'r') as f:
        data = json.load(f)
    data[index]=state
    with open(data_path, 'w') as f:
        json.dump(data, f)
    R.release()

init_state()